/**
 * Created by songj on 2015/12/11.
 */
define(['angular',
    'framework/msg/GillionMsgModule',
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/datasource/DataSourceModule',
    'framework/dropdown/GillionDropdownModule',
    'framework/date/DateModule',
    'angular-underscore'
], function (angular) {
    var module = angular.module('ExecuteTestController',
        ['GillionMsgModule', 'DataGridModule', 'GillionPaginationModule',
            'DataSourceModule', 'DateModule', 'GillionDropdownModule'])
        .controller('ExecuteTestController', ['$scope', 'GillionMsgService',  'Arrays', '$http', 'GillionMsg',
                function ($scope, GillionMsgService, Arrays, $http, GillionMsg) {
                    $scope.mes = GillionMsgService.getInputData();
                    $http({
                        method:'GET',
                        url: '/grule-manager/unitcases',
                        params: {
                            groupId:  $scope.mes.groupId,
                            artifactId: $scope.mes.artifactId
                        }
                    }).success(function (resp) {
                        $scope.unitCases = resp || [];
                    });

                    $scope.checkUnitCase = function(checked, index){
                        $scope.unitCases[index].checked = checked;
                    }

                    $scope.confirm = function() {
                        var selectIds = [];
                        angular.forEach($scope.unitCases, function(unitCase){
                            if (unitCase.checked) {
                                selectIds.push(unitCase.id);
                            }
                        });
                        if (selectIds.length == 0) {
                            GillionMsg.alert('提示', '请选择测试用例！');
                            return;
                        }

                        GillionMsgService.setOutputData(selectIds);
                        GillionMsgService.close();
                    };
                }
            ]
        );

    module.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode(true);
    }]);
    return module;
});
